package books4africa

import java.util.Date;

class RankingController {

	def springSecurityService
	
    def show = {
		
		if(params.bookId)
		{
			def book = Books.findById(params.bookId)
			def results = book.getRanks()
			
			[rankingInstanceList : results, bookResult : book]
		}
		
	}
	
	def save = {
		
		// get user id for user object
		def user =  springSecurityService.getCurrentUser()
		user = User.get(user.id)
		
		// get book object
		def book = Books.get(params.book.id)
		
		def newRank = new Ranking(rank: params.rank, comment: params.comment, user: user, book: book).save()
		
		redirect(controller : "Books", action: "show", id: params.bookId)
	}
	
	def cancel = {
		
		redirect(controller : "Books", action: "show", id: params.bookId)
	}
}
